/**
 * 主屏幕
 * @authors yangchaojun (YYChildren@gmail.com)
 * @date    2018-12-14 18:20:21
 * @version 0.0.1
 */

import { ui } from '../ui/layaMaxUI';
import BrowserUtil from '../util/BrowerUtil';

export default class MainScreen extends ui.MainScreenUI {
    constructor() {
        super();
    }

    public onAwake() {
        Laya.stage.on(Laya.Event.RESIZE, this, this.onResize);
        this.onResize();
    }

    private onResize() {
        let w: number = BrowserUtil.phyWidth;
        let h: number = BrowserUtil.phyHeight;
        let top: number = 0;
        let bottom: number = 0;
        if (BrowserUtil.isHoleScreen) {
            top = BrowserUtil.holeTop;
            bottom = BrowserUtil.holeBottom;
        }
        let scale: number = Math.min(w / Laya.stage.designWidth, (h - top - bottom) / Laya.stage.designHeight);
        let trueW: number = w / scale;
        let trueH: number = h / scale - (top + bottom) * scale;
        if (BrowserUtil.stageWidth != trueW || BrowserUtil.stageHeight != trueH) {
            BrowserUtil.stageWidth = trueW;
            BrowserUtil.stageHeight = trueH;
            this.mainLayer.pos(0, top * scale);
            this.mainLayer.size(trueW, trueH);
        }
    }

    public onEnable() {

    }

    public onDisable() {

    }

}